package edu.neu.cs6515.gui;

import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JPanel;

import edu.neu.cs6515.xml.Tile;

/**
 * to render a Tile
 */
public class TileRenderer extends JPanel {

    private static final long serialVersionUID = 1L;
    private CellRenderer cell0;
    private CellRenderer cell1;

	public static final int WIDTH_PADDING = 8;
	public static final int HEIGHT_PADDING = 2;
    /**
     * C'tor
     * 
     * @param tile
     *            to be rendered
     */
    public TileRenderer(final Tile tile, boolean selected) {
        super();
		if (selected) {
			this.setBorder(BorderFactory.createLoweredBevelBorder());
		}else {
			this.setBorder(BorderFactory.createRaisedBevelBorder());
		}
        this.setPreferredSize(new Dimension(CellRenderer.DIAMETER + WIDTH_PADDING,
                CellRenderer.DIAMETER * 2 + HEIGHT_PADDING));
        this.setLayout(new GridLayout(2, 1));
        initializeCell0AndCell1(tile);
    }

    /**
     * create cell according to tile
     * 
     * @param tile
     *            tile to be rendered
     */
    private void initializeCell0AndCell1(final Tile tile) {
        cell0 = new CellRenderer(0, 0, tile.getC0());
        cell1 = new CellRenderer(0, 0, tile.getC1());
        this.add(cell0);
        this.add(cell1);
    }
}
